import request from '@/utils/request'


export function verifyToken(): Promise<any> {
    return request({
        method: "get",
        url: "/verifyToken"
    })
}

export function versig(params: { message: string, signature: string }): Promise<any> {
    return request({
        method: "post",
        url: "/versig",
        data: formData(params)
    })
}

export function isUserExist(params: any): Promise<any> {
    return request({
        method: "get",
        url: "/isUserExist",
        params
    })
}

export function getUserInfo(): Promise<any> {
    return request({
        method: "get",
        url: "/getUserInfo",
    })
}


export function getParameter(): Promise<any> {
    return request({
        method: "get",
        url: "/getParameter",
    })
}


export function getRentInfo(): Promise<any> {
    return request({
        method: "get",
        url: "/getRentInfo",
    })
}


export function getEnergyAddrList(): Promise<any> {
    return request({
        method: "get",
        url: "/getEnergyAddrList",
    })
}

// https://api.shasta.trongrid.io
// https://api.trongrid.io
export function getaccountresource(params: any): Promise<any> {
    return request({
        method: "get",
        url: "https://api.trongrid.io/wallet/getaccountresource",
        params
    })
}

export function createtransaction(params: any): Promise<any> {
    return request({
        method: "post",
        url: "https://api.trongrid.io/wallet/createtransaction",
        data: params
    })
}

export function insertPreRent(params: any): Promise<any> {
    return request({
        method: "post",
        url: "/insertPreRent",
        data: formData(params)
    })
}
export function updatePreRent(params: any): Promise<any> {
    return request({
        method: "post",
        url: "/updatePreRent",
        data: formData(params)
    })
}

export function getStakeParameter(): Promise<any> { ///
    return request({
        method: "get",
        url: "/getStakeParameter",
    })
}

export function insertPreStake(params: any): Promise<any> {//
    return request({
        method: "post",
        url: "/insertPreStake",
        data: formData(params)
    })
}

export function updatePreStake(params: any): Promise<any> {//
    return request({
        method: "post",
        url: "/updatePreStake",
        data: formData(params)
    })
}

export function updateStake(params: any): Promise<any> {//
    return request({
        method: "post",
        url: "/updateStake",
        data: formData(params)
    })
}

export function send(params: any): Promise<any> {//
    return request({
        method: "post",
        url: "/send",
        data: formData(params)
    })
}


export function getStakeList(params: any): Promise<any> {//
    return request({
        method: "get",
        url: "/getStakeList",
        params
    })
}

export function getSendList(params: any): Promise<any> {//
    return request({
        method: "get",
        url: "/getSendList",
        params
    })
}



export function getStakeInfo(): Promise<any> {//
    return request({
        method: "get",
        url: "/getStakeInfo",
    })
}


export function getNodeCodeById(params: any): Promise<any> {
    return request({
        method: "get",
        url: "/getNodeCodeById",
        params
    })
}

export function getNodeIdByCode(params: any): Promise<any> {
    return request({
        method: "get",
        url: "/getNodeIdByCode",
        params
    })
}


const formData = (params: any) => {
    let formData = new FormData();
    for (let i in params) {
        formData.append(i, params[i])
    }
    return formData
}